import QuickCrypto from 'react-native-quick-crypto';
import { Buffer } from 'buffer';
/**
 * Encrypts a given plaintext using AES encryption.
 *
 * @param src - The plaintext input that needs to be encrypted.
 * @param keyWord - The secret key used for encryption.
 * @returns The encrypted text as a string.
 */
export const passwordRegex = /^(?=.*[a-z]).{6,}$/;

export const emailReg = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const mobileReg = /^1[3-9]\d{9}$/;
export function encrypt(src: string, keyWord: string) {
  // 使用 keyWord 作为 key，生成一个 12 字节的 IV
  const key = Buffer.from(keyWord, 'utf8');
  
  // 创建加密器
  const cipher = QuickCrypto.createCipheriv('aes-128-cfb', key, key);
  const encrypted = cipher.update(src, 'utf8', 'base64');
  const result = encrypted + cipher.final('base64');
  return result;
}

export function testAccount(account: string) {
  return emailReg.test(account) || mobileReg.test(account);
}